/**
 * Created by Bruce on 2016/6/17.
 */
//让某个元素实现动画
function animate(element,target) {
//清除上一次创建的定时器
    if(element.timerId) {
        clearInterval(element.timerId);
    }
    var step = 15;
    //开启定时器
    element.timerId = setInterval(function() {
        //获取当前位置
        var current = element.offsetLeft;
        //判断当前值是否小于目标值
        if(current > target) {
            step = -Math.abs(step);
        }
        if(Math.abs(current - target) > Math.abs(step)) {
            current += step;
            element.style.left = current + "px";
        } else {
            //清除定时器，切换到目标位置
            clearInterval(element.timerId);
            element.style.left = target + "px";
        }
    },15);
}